import express from "express";
const router = express.Router();
import { ValidationError } from "../../../utils/errors";
import { formatResponse } from "../../../utils/tools";
import { IRouterExport } from "../../../common/CommonType";
import { LoginService } from "./Services";

router.post("/login", async (req, res) => {
  if (!req.body.loginId || !req.body.loginPwd) {
    throw new ValidationError("请输入账号密码");
  }
  const result = await LoginService.login(req.body, req);
  res.send(formatResponse(result));
});

router.get("/logout", async (_req: any, res) => {
  res.send(formatResponse(true));
});

const routerInfo: IRouterExport = {
  router,
  requestPath: "/",
  whiteList: [
    {
      path: "/login",
      methods: ["post"],
    },
  ],
};
export default routerInfo;
